<?php

error_reporting(1);

$file="/www/wwwroot/im-server.code688.com/log/hook_log.txt";

$target = '/www/wwwroot/im-server.code688.com'; // 生产环境web目录

$token = '111';
$wwwUser = 'www';
$wwwGroup = 'www';

$json  =file_get_contents("php://input");

$data = json_decode($json,true);

file_put_contents($file,$json.PHP_EOL,FILE_APPEND);

if (empty($data['password']) || $data['password'] !== $token) {
    file_put_contents($file,time()."密码错误");
    exit('error request');
}



// $cmds = array(
//     "cd $target && git pull",
//     "chown -R {$wwwUser}:{$wwwGroup} $target/",
// );

// foreach ($cmds as $cmd) {
//     shell_exec($cmd);
// }

// 感谢@墨迹凡指正，可以直接用www用户拉取代码而不用每次拉取后再修改用户组

$cmd = "cd {$target} && git reset --hard && git pull origin master   ";

$info=shell_exec($cmd);

print_r($info);



